home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / yacas_alg / yacas_morphos / share / yacas / include / mathuserfunc.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  3.4 KB  |  112 lines

  1.  
  2. #ifndef __mathuserfunc_h__
  3. #define __mathuserfunc_h__
  4.  
  5. #include "yacasbase.h"
  6. #include "lispuserfunc.h"
  7. #include "grower.h"
  8.  
  9. class PatternClass;
  10.  
  11. class BranchingUserFunction : public LispArityUserFunction
  12. {
  13. public:
  14.     class BranchParameter : public YacasBase
  15.     {
  16.     public:
  17.         BranchParameter(LispStringPtr aParameter,
  18.                         LispInt aHold=LispFalse)
  19.             : iParameter(aParameter), iHold(aHold) {}
  20.         LispStringPtr iParameter;
  21.         LispInt       iHold;
  22.     };
  23.     class BranchRuleBase : public YacasBase
  24.     {
  25.     public:
  26.         virtual ~BranchRuleBase();
  27.         virtual LispBoolean Matches(LispEnvironment& aEnvironment, LispPtr* aArguments) = 0;
  28.         virtual LispInt Precedence() const = 0;
  29.         virtual LispPtr& Body() = 0;
  30.     };
  31.     class BranchRule : public BranchRuleBase
  32.     {
  33.     public:
  34.         virtual ~BranchRule();
  35.         BranchRule(LispInt aPrecedence,LispPtr& aPredicate,LispPtr& aBody)
  36.         {
  37.             iPrecedence = aPrecedence;
  38.             iPredicate.Set(aPredicate.Get());
  39.             iBody.Set(aBody.Get());
  40.         }
  41.         virtual LispBoolean Matches(LispEnvironment& aEnvironment, LispPtr* aArguments);
  42.         virtual LispInt Precedence() const;
  43.         virtual LispPtr& Body();
  44.     protected:
  45.         BranchRule() {};
  46.     protected:
  47.         LispInt iPrecedence;
  48.         LispPtr iBody;
  49.         LispPtr iPredicate;
  50.     };
  51.     class BranchRuleTruePredicate : public BranchRule
  52.     {
  53.     public:
  54.         BranchRuleTruePredicate(LispInt aPrecedence,LispPtr& aBody)
  55.         {
  56.             iPrecedence = aPrecedence;
  57.             iBody.Set(aBody.Get());
  58.         }
  59.         virtual LispBoolean Matches(LispEnvironment& aEnvironment, LispPtr* aArguments);
  60.     };
  61.     
  62.     class BranchPattern : public BranchRuleBase
  63.     {
  64.     public:
  65.         virtual ~BranchPattern();
  66.         BranchPattern(LispInt aPrecedence,LispPtr& aPredicate,LispPtr& aBody)
  67.         {
  68.             iPatternClass = NULL;
  69.             iPrecedence = aPrecedence;
  70.             iPredicate.Set(aPredicate.Get());
  71.  
  72.             GenericClass *gen = aPredicate.Get()->Generic();
  73.             Check(gen != NULL,KLispErrInvalidArg);
  74.             Check(StrEqual(gen->TypeName(),"\"Pattern\""),KLispErrInvalidArg);
  75.  
  76.             iPatternClass = (PatternClass*)gen;
  77.             iBody.Set(aBody.Get());
  78.         }
  79.         virtual LispBoolean Matches(LispEnvironment& aEnvironment, LispPtr* aArguments);
  80.         virtual LispInt Precedence() const;
  81.         virtual LispPtr& Body();
  82.     private:
  83.         LispInt iPrecedence;
  84.         LispPtr iBody;
  85.         LispPtr iPredicate;
  86.         PatternClass *iPatternClass;
  87.     };
  88.  
  89.     BranchingUserFunction(LispPtr& aParameters);
  90.     virtual ~BranchingUserFunction();
  91.     virtual void Evaluate(LispPtr& aResult,LispEnvironment& aEnvironment,
  92.                   LispPtr& aArguments);
  93.     virtual void HoldArgument(LispStringPtr aVariable);
  94.     virtual LispInt Arity() const;
  95.     virtual void DeclareRule(LispInt aPrecedence, LispPtr& aPredicate,
  96.                              LispPtr& aBody);
  97.     virtual void DeclareRule(LispInt aPrecedence, LispPtr& aBody);
  98.     void DeclarePattern(LispInt aPrecedence, LispPtr& aPredicate,
  99.                         LispPtr& aBody);
  100.     void InsertRule(LispInt aPrecedence,BranchRuleBase* newRule);
  101.     virtual LispPtr& ArgList();
  102.     
  103. private:
  104.     CArrayGrower<BranchParameter> iParameters;
  105.     CDeletingArrayGrower<BranchRuleBase*>     iRules;
  106.     LispPtr iParamList;
  107. };
  108.  
  109.  
  110. #endif
  111.  
  112.